package com.tianfeng.news.ui;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.tianfeng.news.R;
import com.tianfeng.news.globle.ConstantUrl;
import com.tianfeng.news.model.bean.UserBean;
import com.tianfeng.news.model.bean.wenda.WIthdrawBean;
import com.tianfeng.news.net.HttpView;
import com.tianfeng.news.net.OkHttpHelper;
import com.tianfeng.news.ui.activity.base.BaseActivity;
import com.tianfeng.news.ui.activity.other.ContactKeFuActivity;
import com.tianfeng.news.utils.UIUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class WithdrawActivity extends BaseActivity implements HttpView {
    @Nullable
    @BindView(R.id.tv_back)
    public TextView mTvBack;

    @Nullable
    @BindView(R.id.tvname)
    public TextView tvname;

    @Nullable
    @BindView(R.id.tvacc)
    public TextView tvacc;

    @Nullable
    @BindView(R.id.tvtime)
    public TextView tvtime;

    @Nullable
    @BindView(R.id.tvstate)
    public TextView tvstate;
    @Nullable
    @BindView(R.id.ll_lianxi)
    public LinearLayout ll_lianxi;

    @Override
    public int getContentLayout() {
        return R.layout.activity_withdraw;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initView(View rootView, Bundle savedInstanceState) {
        setStatusBarImmersive(null);
        mTvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ll_lianxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(WithdrawActivity.this,ContactKeFuActivity.class));
            }
        });
//        mTvDesc.setText(Html.fromHtml(html));
    }

    /**
     * 设置返回键的文字
     *
     * @param text
     */
    public void setBackText(String text) {
        setBackTextAndDrawable(text, -1);
    }

    /**
     * 设置返回键的文字和图片；
     *
     * @param text
     * @param resImgId
     */
    public void setBackTextAndDrawable(String text, int resImgId) {

        if (mTvBack != null) {
            mTvBack.setVisibility(View.VISIBLE);
            mTvBack.setText(text);
            if (resImgId > -1) {
                Drawable drawable = ContextCompat.getDrawable(this, resImgId);
                drawable.setBounds(0, 0, UIUtils.dip2px(this, 25), UIUtils.dip2px(this, 25));
                mTvBack.setCompoundDrawables(drawable, null, null, null);
            }
        }
    }

    @Override
    public void setTitle(int titleId) {
        super.setTitle(R.string.cc);
    }




    @Override
    protected void initData() {
        super.initData();
        getInidata();
    }

    public void getInidata() {
        UserBean userBean = ((BaseActivity) WithdrawActivity.this).getUserBean();
        if (userBean == null) {
            return;
        }
        HashMap<String, String> params = new HashMap<>();
        params.put("userid", userBean.getUserid());
        OkHttpHelper.getAsyncHttp(this, 10001, params, ConstantUrl.REQUEST_JINDU, this);

    }

    @Override
    public void onSuccessResult(int requestCode, int returnCode, String returnMsg, String returnData, Map<String, String> paramsMaps) {
        Gson gson = new Gson();
        WIthdrawBean wIthdrawBean = gson.fromJson(returnData, WIthdrawBean.class);
        List<WIthdrawBean.DataBean> data = wIthdrawBean.getData();
        WIthdrawBean.DataBean dataBean = data.get(0);

        String html1="<html>提现真实姓名:  <font color="+getResources().getColor(R.color.base_color_blue)+">"+dataBean.getUseracc()+"</font></html>";
        String html2="<html>提现账号:  <font color="+getResources().getColor(R.color.base_color_blue)+">"+dataBean.getTixianzhanghao()+"</font></html>";
        String html3="<html>提现账号:  <font color="+getResources().getColor(R.color.base_color_blue)+">"+dataBean.getAddtime()+"</font></html>";
        String html4="<html>提现账号:  <font color="+getResources().getColor(R.color.red_color)+">"+dataBean.getUserdesc()+"</font></html>";

        tvname.setText(Html.fromHtml(html1));

        tvacc.setText(Html.fromHtml(html2));
        tvtime.setText(Html.fromHtml(html3));
        tvstate.setText(Html.fromHtml(html4));

    }

    @Override
    public void onFailure(int callbackId, String data) {

    }
}


